﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects.DataClasses;
using System.Data.Objects;

namespace Ovvio.Business
{
    public class ServiceList<TEntity, TObjectContext>
        where TEntity : EntityObject, new()
        where TObjectContext : ObjectContext, new()
    {
        private string _entitySet;
        public ServiceList() : this(string.Empty)
        { }

        public ServiceList(string entitySet)
        {
            if (string.IsNullOrEmpty(entitySet))
                _entitySet = EntityDefaults.GetEntitySet<TEntity>();
            else
                _entitySet = entitySet;
        }

        public IList<TEntity> GetEntities()
        {
            using (var ctx = new TObjectContext())
            {
                var query = ctx.CreateQuery<TEntity>("[" + _entitySet + "]");
                return query.ToList();
            }
        }
    }
}
